package com.fnzx.controller;

import java.util.Arrays;
import java.util.Map;

import com.fasterxml.jackson.annotation.JsonTypeInfo;
import com.fnzx.entity.ArticleEntity;
import com.fnzx.entity.ExpertEntity;
import com.fnzx.service.ExpertService;
import com.fnzx.util.PageUtils;
import com.fnzx.util.R;

import com.fnzx.util.oss.OssUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import springfox.documentation.annotations.ApiIgnore;


/**
 * @author chenshun
 * @email sunlightcs@gmail.com
 * @date 2021-10-07 10:54:12
 */
@RestController
@RequestMapping("iot/expert")
@Api(tags ="专家模块")
public class ExpertController {
    @Autowired
    private ExpertService expertService;

    /**
     * 列表
     */
    @ApiOperation(value = "前台页面-分页查询",notes = "查询出所有专家")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page",value = "当前页",paramType = "query",required = true,dataType = "String"),
            @ApiImplicitParam(name = "limit",value = "每页记录数",paramType = "query",required = true,dataType = "String")
    })
    @GetMapping("/list")
    public R list(@ApiIgnore @RequestParam Map<String, Object> params){
        PageUtils page = expertService.queryPage(params);
        return R.ok().put("page", page);
    }

    /**
     * 信息
     */
    @ApiOperation(value = "前台页面-id查询",notes = "通过id查询出专家")
    @GetMapping("/info/{id}")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id",value = "专家id",paramType = "path",required = true,dataType = "String"),
    })
    public R info(@PathVariable("id") String id){
		ExpertEntity expert = expertService.getById(id);
        return R.ok().put("expert", expert);
    }





    @ApiOperation(value = "前台页面-姓名查询",notes = "通过专家姓名查询出专家")
    @GetMapping("/info")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page",value = "当前页",paramType = "query",required = true,dataType = "String"),
            @ApiImplicitParam(name = "limit",value = "每页记录数",paramType = "query",required = true,dataType = "String"),
            @ApiImplicitParam(name = "name",value = "专家姓名",paramType = "path",required = true,dataType = "String")
    })
    public R info(@ApiIgnore @RequestParam Map<String, Object> params){
        PageUtils page  = expertService.queryPageByTitle(params);
        return R.ok().put("page", page);
    }
    /**
     * 保存
     */
    @ApiOperation(value = "前端页面-添加", notes = "添加专家{\n" +
            "\t\"areas\": \"1111\",\n" +
            "\t\"assumeOffice\": \"111\",\n" +
            "\t\"degree\": \"111\",\n" +
            "\t\"name\": \"111\",\n" +
            "\t\"picture\": \"1111\",\n" +
            "\t\"profession\": \"111\",\n" +
            "\t\"program\": \"111\"\n" +
            "}")
    @PostMapping("/save")
    public R save(@RequestBody ExpertEntity expertEntity,
                  @RequestHeader String token) {
        expertService.save(expertEntity);
        return R.ok();
    }

    /**
     * 修改
     */
    @ApiOperation(value = "后台页面-修改", notes = "修改专家{\n" +
            "\t\"areas\": \"222\",\n" +
            "\t\"assumeOffice\": \"2222\",\n" +
            "\t\"degree\": \"222\",\n" +
            "\t\"id\": 1454799497843081217,\n" +
            "\t\"name\": \"222\",\n" +
            "\t\"picture\": \"222\",\n" +
            "\t\"profession\": \"222\",\n" +
            "\t\"program\": \"2222\"\n" +
            "}")
    @PostMapping("/update")
    public R update(@RequestBody ExpertEntity expertEntity,
                    @RequestHeader String token ){
        expertService.updateById(expertEntity);
        return R.ok();
    }

    /**
     * 删除
     */
    @ApiOperation(value = "后台页面-删除", notes = "删除专家，可以同时删除多个")
    @PostMapping("/delete")
    public R delete(@RequestBody Long[] ids,
                    @RequestHeader String token) {
            expertService.removeByIds(Arrays.asList(ids));
            return R.ok();
    }

}

